package cn.tedu.rebbimq.m3_publishsubscrube;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        f.setVirtualHost("/ryan");

        Channel c = f.newConnection().createChannel();

        //定义交换机 fanout 扇形交换机
        c.exchangeDeclare("jhj", BuiltinExchangeType.FANOUT);

        //向交换机发消息
        while (true) {
            System.out.println("输入消息: ");
            String msg = new Scanner(System.in).nextLine();
            c.basicPublish("jhj", "", null, msg.getBytes()); //"" 空串的意思是群发不需要指定队列,也可以设置一个队列,但没有实际意义

        }

    }
}
